package com.etc.service.impl;

import com.etc.dao.UserDao;
import com.etc.pojo.User;
import com.etc.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao dao;
    //加入事务
    @Transactional
    @Override
    public boolean register(User user) {
        Integer b = dao.addUser(user);
        if (b>0){
            return true;
        }
        return false;
    }

    @Override
    public User login(String userName, String password) {
        return dao.queryUserByUserNameAndPassword(userName,password);
    }

    @Override
    public List<User> getQueryAllUsers() {
        return dao.queryAllUsers();
    }

    @Override
    public PageInfo<User> getQueryAllUser(Integer pageNo, Integer pageSize) {
        //1.开启分页
        PageHelper.startPage(pageNo, pageSize);
        //2.执行查询
        List<User> list = dao.queryAllUsers();
        //3.包装
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return  pageInfo;
    }


    @Override
    public boolean getUpdateUser(User user) {
        return dao.updateUser(user);
    }

    @Override
    public boolean updateUser3(User user) {
        return dao.updateUser3(user);
    }

    @Override
    public boolean updateUser4(User user) {
        return dao.updateUser4(user);
    }

    @Override
    public boolean getDeleteUser(String userId, int userState) {
        int i = dao.deleteUser(userId,userState);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateUser(User user) {
        return dao.updateUser(user);
    }

    @Override
    public boolean updateUser2(User user) {
        return dao.updateUser2(user);
    }

    @Override
    public User getUserByUserId(String userId) {
        return dao.queryUserByUserId(userId);
    }

    @Override
    public User getQueryUserByUserName(String userName) {
        return dao.queryUserByUserName(userName);

    }


    @Override
    public User adminLogin(String userName, String password) {
        return dao.queryUserAdmin(userName,password);
    }

    @Override
    public User getQueryAdminUserName(String userName) {
        return dao.queryAdminUserName(userName);}

    @Override
    public boolean insertVipInfo(String userId) {
        return dao.insertVipInfo(userId)>0;
    }
}
